package com.example.yucheng.mapper;

import com.example.yucheng.domain.*;
import org.apache.ibatis.annotations.*;

import java.sql.Date;
import java.util.List;

@Mapper
public interface OutboundMapper {
//    @Select("SELECT * FROM outbound_order order by time limit #{pageNum},#{pageSize}")
    OutboundOrder getOutboundOrderList(String orderNo);

//    @Select("SELECT * FROM outbound_order order by time desc limit #{pageNum},#{pageSize}")
    List<OutboundOrder> setSort( String receivingUnit, String goodName, Date startTime, Date endTime);

    @Select("SELECT * FROM outbound_order")
    List<OutboundOrder> getAllOutboundOrderList(Integer pageNum, Integer pageSize);

//    @Select("select * from outbound_good where order_no=#{orderNo}")
List<OutboundUnit> getOutboundOrderDetail(Integer oId);

    @Update("update outbound_order set  entry_person = #{entryPerson} , receiving_unit =#{receivingUnit} where order_no = #{orderNo}")
    void updateOutboundOrder(OutboundOrder outboundOrder);

    @Delete("delete from outbound_order where order_no = #{orderNo}")
    void deleteOutboundOrder(@Param("orderNo")String orderNo);

    @Insert("insert outbound_order set order_no=#{orderNo},sum_number=#{sumNumber},time=NOW(),entry_person=#{entryPerson},receiving_unit=#{receivingUnit},remark=#{remark}")
    void addOutboundOrder(OutboundOrder outboundOrder);

    @Insert("insert outbound_good set g_id=#{gId} , c_id=#{cId},number=#{number},cost_price=#{costPrice},per=#{per},order_no=#{orderNo},remark=#{remark}")
    void addOutboundGood(OutboundGood outboundGood);

//    @Select("select * from loss ")
    List<Loss> getLossList();

    @Select("select name from stock where name like '%#{text}%'")
    String findGoodName(String text);

    @Select("select name from stock where id=#{gId}")
    Stock findGoodNameById(int gId);

    @Insert("insert loss set g_id=#{gId} , number=#{number},cost_price=#{costPrice},remark=#{remark}")
    void addLoss(Loss loss);

    @Delete("delete from loss where id =#{id}")
    void deleteLossById(int id);

    @Select("select * from outbound_order where order_no =#{orderNo}")
    OutboundOrder findOutboundOrderByOrderNo(String orderNo);


    List<OutboundOrder> getOutboundOrdeNo(String receivingUnit, String goodName, Date startTime, Date endTime);

    @Select("select * from loss where id = #{id}")
    Loss getLossById(int id);

    @Insert("insert outbound_good set g_id =#{id},remark=#{remark}")
    void addGoodList(Integer id, String remark);

    @Insert("insert outbound_unit set r_id=#{rId},number=#{number},remark=#{remark},department=#{department},o_id=#{oId},per=#{per},cost_price=#{costPrice},receiving_person=#{receivingPerson}")
    void addOutboundUnit(@Param("rId") Integer rId, @Param("receivingPerson")String receivingPerson, @Param("department")String department, @Param("good")Stock good,@Param("oId")Integer oId, @Param("number") double number,@Param("remark") String remark,@Param("per") String per,@Param("costPrice") double costPrice);

    @Select("select id from outbound_good where g_id=#{id}")
    int getOutGoodIdByGid(Integer id);

    List<OutboundGood> getOutboundGoodList(@Param("gId") Integer gId);

    @Select("select * from outbound_good")
    List<OutboundGood> getAllOutboundGoodList();

    @Select("select * from outbound_unit where o_id =#{id}")
    List<OutboundUnit> getboundUnit(Integer id);


    List<OutboundGood> getGoodInfo(Integer oId);

//    @Update("update outbound_unit  set number = #{number},cost_price=#{costPrice},remark= #{remark},per=#{per} where id = #{id}")
    void updateOutboundDetail(OutboundUnit outboundUnit);

    @Select("select outbound_good.id  from outbound_unit join outbound_good on o_id = outbound_good.id where outbound_unit.id = #{id}")
    OutboundGood findOutboundGood();

    @Update("update outbound_good set g_id =#{gId} where id =#{id}")
    void updateOutboundGoodInfo(Integer id, Integer gId);

    @Delete("delete from outbound_unit where id = #{id}")
    void deleteOutboundUnit(int id);

    @Select("select * from outbound_good where g_id =#{id}")
    OutboundGood getOutboundByGid(Integer id);
}
